<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>购物车</title>
    <link href ="{$Think.const.CSS_URL}checkOut.css" rel="stylesheet" type="text/css" />
    <link href ="{$Think.const.CSS_URL}style.css" rel="stylesheet" type="text/css" media="all" />
    <link href ="{$Think.const.CSS_URL}bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href ="{$Think.const.CSS_URL}megamenu.css" rel="stylesheet" type="text/css" media="all" />


    <script type="text/javascript" src ="{$Think.const.JS_URL}jquery-2.2.3.min.js"></script>
    <script type="text/javascript" src ="{$Think.const.JS_URL}bootstrap.js"></script>


</head>
<body leftmargin="0" topmargin="0" rightmargin = "0">
     <iframe class = "checkOutHead" src = "__MODULE__/Index/indexHead" scrolling="no"></iframe>
     <!--导航栏-->
     <div class="navbar navbar-default shadow" role="navigation">
         <div class = "container">
             <ul class="nav navbar-nav">
                 <li class="active"><a href="__MODULE__/Index/index">主页</a></li>
                 <li class="dropdown">
                     <a href="##" data-toggle="dropdown" class="dropdown-toggle">蜂蜜种类<span class="caret"></span></a>
                     <ul class="dropdown-menu">
                         <li><a href="__MODULE__/Goods/product">全部分类</a></li>
                         <li><a href="__MODULE__/Goods/product?type=classify&keyWord=蜂蜜">蜂蜜</a></li>
                         <li><a href="__MODULE__/Goods/product?type=classify&keyWord=蜂胶">蜂胶</a></li>
                         <li><a href="__MODULE__/Goods/product?type=classify&keyWord=花粉">花粉</a></li>
                         <li><a href="__MODULE__/Goods/product?type=classify&keyWord=蜂皇浆">蜂皇浆</a></li>
                     </ul>
                 </li>
                 <li><a href="http://www.360doc.com/content/14/1113/19/16901590_424885250.shtml" target="_blank">蜂蜜养生</a></li>
                 <li><a href="##">加盟我们</a></li>
                 <li><a href="##">关于三生锁</a></li>
             </ul>
             <form action="__MODULE__/Goods/product" class="navbar-form navbar-right" rol="search">
                 <div class="form-group">
                     <input type="text" class="form-control" placeholder="请输入关键词" />
                 </div>
                 <button type="submit" class="btn btn-default">搜索</button>
             </form>
         </div>
     </div>

     <div class="container">
         <div class="check">
             <div class="col-md-3 cart-total">
                 <a class="continue" href="__MODULE__/Index/index" id="continue">继续购物</a>
                 <form action="order" method="post">
                     <input type="hidden" id="p_id" name = "p_id" value = "">
                     <input type="hidden" id="count" name = "count2" value = "">
                     <input type="hidden" name = "state" value="已完成">
                     <input type="hidden" id="u_id" name = "u_id" value = "{$Think.session.u_id}">
                     <input type="hidden" id="o_price" name = "o_price" value="">
                     <div class="price-details">
                         <h3>账单详情</h3>
                         <span>商品总价</span>
                         <span class="total" id="total_price"></span>
                         <span>折扣率(店铺活动)</span>
                         <span class="total" id="discount">10%</span>
                         <span>优惠总价</span>
                         <span class="total" id="discount_price"></span>
                         <span>运费(满120包邮)</span>
                         <span class="total" id="carriage">10</span>
                         <div class="clearfix"></div>
                     </div>
                     <ul class="total_price">
                         <li class="last_price"> <h4>折后总价</h4></li>
                         <li class="last_price"><span id="last_price" name = "last_price"></span></li>
                         <div class="clearfix"> </div>
                     </ul>
                     <div class="clearfix"></div>
                     <div class="total-item">
                         <input type="text" class = "form-control" name="address" placeholder="请输入您的地址" required = "required">
                         <input type="text" class = "form-control" name="phone" placeholder="请输入您的手机" required = "required">
                         <input type="text" class = "form-control" name="name" placeholder="请输入收货人姓名" required = "required">
                     </div>
                     <input type="submit" id = "submit" class="btn btn-success" value="确定付款"/>
                 </form>
             </div>
             <!--{$pro.p_id}-->
             <div class="col-md-9 cart-items">
                 <div class = "hidden" id = "tips">
                     <a href="__MODULE__/Goods/product">
                         <img src="{$Think.const.img_url}bee.jpg">
                         <span >点我，快点我！猛击我添加商品哦！</span>
                     </a>
                 </div>
                 <volist name="pro_list" id="pro">
                     <span class = "hidden" name = "pro_id">{$pro.p_id}</span>
                     <div class="cart-header">
                         <a href="__MODULE__/Goods/delShoppingCar?p_id={$pro.p_id}&u_id={$Think.session.u_id}"><div class="close1"></div></a>
                         <div class="cart-sec simpleCart_shelfItem">
                             <div class="cart-item cyc">
                                 <img src="{$pro.img1}" class="img-responsive"/>
                             </div>
                             <div class="cart-item-info">
                                 <ul class="qty">
                                     <li><p>重量 : {$pro.weight}g</p></li>
                                     <li><p>数量 :<span name = "count">{$pro.count}</span></p></li>
                                 </ul>
                                 <div class="delivery">
                                     <p>单价 : <span name = "price">{$pro.price}</span></p>
                                     <div class="clearfix"></div>
                                 </div>
                                 <div class="fgh">
                                     <a href="__MODULE__/Goods/favor?type=add&p_id={$pro.p_id}&u_id={$Think.session.u_id}">添加到收藏夹</a>
                                 </div>
                             </div>
                             <div class="clearfix"></div>
                         </div>
                     </div>
                 </volist>
                 <ul class="pagination">
                     　　{$page}
                 </ul>
             </div>
             <div class="clearfix"> </div>
         </div>
     </div>
</body>
</html>
<script>
    $(window).load(function() {
        getPid();
        getCount();
        getTotalPrice();
        $("#submit").click(function() {
            if ($('#o_price').val() == 0.00) {
                alert("购物车为空,请先添加购物车");
                return false;
            }
        });
    });
    function getPid(){
        var p_id = document.getElementsByName("pro_id");
        var pid_info = "";
        for(var i = 0;i<p_id.length;i++){
            if(i != p_id.length-1)
                pid_info += p_id[i].innerHTML + ",";
            else
                pid_info += p_id[i].innerHTML;
        }
        $('#p_id').attr('value',pid_info);
    }

    function getCount(){
        var count = document.getElementsByName("count");
        var count_info = "";
        for(var i = 0;i<count.length;i++){
            if(i != count.length-1)
                count_info += count[i].innerHTML + ",";
            else
                count_info += count[i].innerHTML;
        }
        $('#count').attr('value',count_info);
    }

    function getTotalPrice(){
        var count = document.getElementsByName("count");
        var price = document.getElementsByName("price");
        var carriage = document.getElementById("carriage");
        var TotalPrice = 0;
        for(var i = 0;i<count.length;i++){
            TotalPrice += count[i].innerHTML * price[i].innerHTML;
        }
        if(TotalPrice >= 120||TotalPrice == 0){
            carriage.textContent =0;
        }
        var discount_price = (TotalPrice*0.1).toFixed(2);
        var last_price = (TotalPrice - discount_price + Number(carriage.textContent)).toFixed(2);
        $("#discount_price").text(discount_price);
        $("#total_price").text(TotalPrice);
        $("#last_price").text(last_price);
        $('#o_price').attr('value',last_price);

        if(TotalPrice == 0){
            $('#tips').removeClass("hidden");
        }
    }


</script>